package com.link.base.base.feedback.controller;


import com.link.base.base.feedback.model.Feedback;
import com.link.base.base.feedback.service.FeedbackService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/12 9:48
 * @version 1.0
 */

@Controller
@RequestMapping("/link/feedback")
public class FeedbackController extends BasicController<Feedback> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private FeedbackService feedbackService;

    @Override
    public BasicService<Feedback> getBasicService() throws Exception {
        return feedbackService;
    }


    /**
     * 插入前做操作
     */
    @Override
    public void beforInsert(Feedback entity, HttpServletRequest request) throws Exception {


    }

    /**
     * 新建默认值
     */
    @Override
    @RequestMapping(value = "/preDefaultValue", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> preDefaultValue(@JsonParam Feedback entity, HttpSession session, HttpServletRequest request,
                                               HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            Feedback feedback = new Feedback();
            feedback.setId(keyGenerateService.keyGenerate());
            feedback.setOrigin("CRM");
            result.put("success", true);
            result.put("result", feedback);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
